import requests

# 网页采集器
# UA监测
# UA：User-Agent(请求载体的身份标识）
# UA伪装

if __name__ == '__main__':
    # UA 伪装
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
    }
    # 指定url
    url = "https://www.sogou.com/web"
    # 处理url携带的参数：封装到字典中
    kw = input("enter a word:")
    param = {
        "query": kw,
    }

    # 发起请求
    response = requests.get(url=url, params=param, headers=headers)

    # 获取响应数据
    page_text = response.text

    # 持久化存储
    filename = kw + ".html"
    with open(filename, "w", encoding="utf-8") as fp:
        fp.write(page_text)
    print(filename, "保存成功！！！")
